🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / desktopApp / src / main / kotlin / org / meshtastic / desktop / DesktopNotificationManager.kt
Displaying Raw • Download
desktopApp/src/main/kotlin/org/meshtastic/desktop/DesktopNotificationManager.kt fix/qr-error-correction (7b45f84f) Text, 5.64 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.desktop
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.CancellationException
Tff7b72import T7ee787kotlinx.coroutines.Dispatchers
Tff7b72import T7ee787kotlinx.coroutines.flow.MutableSharedFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.SharedFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.asSharedFlow
Tff7b72import T7ee787kotlinx.coroutines.withContext
Tff7b72import T7ee787org.meshtastic.core.repository.Notification
Tff7b72import T7ee787org.meshtastic.core.repository.NotificationManager
Tff7b72import T7ee787org.meshtastic.core.repository.NotificationPrefs
Tff7b72import T7ee787org.meshtastic.desktop.notification.NativeNotificationSender
Tff7b72import T7ee787androidx.compose.ui.window.Notification Tff7b72as Te6edf3ComposeNotification
T8b949e/**
* Desktop notification manager that dispatches domain [Notification] objects to native OS notifications.
*
* Uses platform-specific [NativeNotificationSender] implementations (libnotify on Linux, `UNUserNotificationCenter` on
* macOS, PowerShell toast on Windows) for proper native look-and-feel. Falls back to Compose Desktop tray notifications
* (via [fallbackNotifications]) when the native sender is unavailable or fails.
*
* Native sends run on [Dispatchers.IO] within the suspending [dispatch] call, so the returned Boolean reflects the
* resolved outcome (native success, or acceptance by the tray fallback) rather than an optimistic guess.
*
* Registered manually in `desktopPlatformStubsModule` -- do **not** add `@Single` to avoid double-registration with the
* `@ComponentScan("org.meshtastic.desktop")` in [DesktopDiModule][org.meshtastic.desktop.di.DesktopDiModule].
*/
Tff7b72class T56d364DesktopNotificationManagerTb4b4b4(
Tff7b72private Tff7b72val Te6edf3prefsTb4b4b4: Te6edf3NotificationPrefsTb4b4b4,
Tff7b72private Tff7b72val Te6edf3nativeSenderTb4b4b4: Te6edf3NativeNotificationSenderTb4b4b4,
Tb4b4b4) Tb4b4b4: Te6edf3NotificationManager Tb4b4b4{
Tff7b72init Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{ Ta5d6ff"Ta5d6ffDesktopNotificationManager initialized (native sender: Tffd700${Te6edf3nativeSenderTff7b72::Te6edf3classTb4b4b4.Te6edf3simpleNameTffd700}Ta5d6ff)Ta5d6ff" Tb4b4b4}
Tb4b4b4}
Tff7b72private Tff7b72val Te6edf3_fallbackNotifications Tff7b72= Te6edf3MutableSharedFlowTff7b72<Te6edf3ComposeNotificationTff7b72>Tb4b4b4(Te6edf3extraBufferCapacity Tff7b72= T79c0ff1T79c0ff0Tb4b4b4)
T8b949e/**
* Fallback flow of Compose [ComposeNotification] objects, emitted only when the native sender fails. Collected by
* the tray composable in Main.kt as a last resort.
*/
Tff7b72val Te6edf3fallbackNotificationsTb4b4b4: Te6edf3SharedFlowTff7b72<Te6edf3ComposeNotificationTff7b72> Tff7b72= Te6edf3_fallbackNotificationsTb4b4b4.Te6edf3asSharedFlowTb4b4b4(Tb4b4b4)
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffInjectDispatcherTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4)
Tff7b72override Tff7b72suspend Tff7b72fun Td2a8ffdispatchTb4b4b4(Te6edf3notificationTb4b4b4: Te6edf3NotificationTb4b4b4)Tb4b4b4: Tffa657Boolean Tb4b4b4{
Tff7b72val Te6edf3enabled Tff7b72=
Tff7b72when Tb4b4b4(Te6edf3notificationTb4b4b4.Te6edf3categoryTb4b4b4) Tb4b4b4{
Te6edf3NotificationTb4b4b4.Te6edf3CategoryTb4b4b4.Te6edf3Message Tff7b72-Tff7b72> Te6edf3prefsTb4b4b4.Te6edf3messagesEnabledTb4b4b4.Te6edf3value
Te6edf3NotificationTb4b4b4.Te6edf3CategoryTb4b4b4.Te6edf3NodeEvent Tff7b72-Tff7b72> Te6edf3prefsTb4b4b4.Te6edf3nodeEventsEnabledTb4b4b4.Te6edf3value
Te6edf3NotificationTb4b4b4.Te6edf3CategoryTb4b4b4.Te6edf3MeshBeacon Tff7b72-Tff7b72> Te6edf3prefsTb4b4b4.Te6edf3nodeEventsEnabledTb4b4b4.Te6edf3value
Te6edf3NotificationTb4b4b4.Te6edf3CategoryTb4b4b4.Te6edf3Battery Tff7b72-Tff7b72> Te6edf3prefsTb4b4b4.Te6edf3lowBatteryEnabledTb4b4b4.Te6edf3value
Te6edf3NotificationTb4b4b4.Te6edf3CategoryTb4b4b4.Te6edf3Alert Tff7b72-Tff7b72> Tff7b72true
Te6edf3NotificationTb4b4b4.Te6edf3CategoryTb4b4b4.Te6edf3Service Tff7b72-Tff7b72> Tff7b72true
Tb4b4b4}
Te6edf3LoggerTb4b4b4.Te6edf3d Tb4b4b4{ Ta5d6ff"Ta5d6ffDesktopNotificationManager dispatch: category=Tffd700${Te6edf3notificationTb4b4b4.Te6edf3categoryTffd700}Ta5d6ff, enabled=Tffd700$Te6edf3enabledTa5d6ff" Tb4b4b4}
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3enabledTb4b4b4) Tff7b72return Tff7b72false
Tff7b72return Te6edf3withContextTb4b4b4(Te6edf3DispatchersTb4b4b4.Te6edf3IOTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3success Tff7b72=
Tff7b72try Tb4b4b4{
Te6edf3nativeSenderTb4b4b4.Te6edf3sendTb4b4b4(Te6edf3notificationTb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3CancellationExceptionTb4b4b4) Tb4b4b4{
Tff7b72throw Te6edf3e
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
T8b949e// Native senders shell out to OS tools / JNA; guard against any unexpected throw so fire-and-forget
T8b949e// callers still get the tray fallback instead of silently swallowing the failure.
Te6edf3LoggerTb4b4b4.Te6edf3eTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffNative notification send threw: Tffd700${Te6edf3notificationTb4b4b4.Te6edf3titleTffd700}Ta5d6ff" Tb4b4b4}
Tff7b72false
Tb4b4b4}
Tff7b72if Tb4b4b4(Te6edf3successTb4b4b4) Tb4b4b4{
Tff7b72true
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3w Tb4b4b4{ Ta5d6ff"Ta5d6ffNative notification failed, falling back to tray: Tffd700${Te6edf3notificationTb4b4b4.Te6edf3titleTffd700}Ta5d6ff" Tb4b4b4}
Te6edf3emitFallbackTb4b4b4(Te6edf3notificationTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
T8b949e/** Returns true when the tray fallback accepted the notification. */
Tff7b72private Tff7b72fun Td2a8ffemitFallbackTb4b4b4(Te6edf3notificationTb4b4b4: Te6edf3NotificationTb4b4b4)Tb4b4b4: Tffa657Boolean Tb4b4b4{
Tff7b72val Te6edf3composeType Tff7b72=
Tff7b72when Tb4b4b4(Te6edf3notificationTb4b4b4.Te6edf3typeTb4b4b4) Tb4b4b4{
Te6edf3NotificationTb4b4b4.Te6edf3TypeTb4b4b4.Te6edf3None Tff7b72-Tff7b72> Te6edf3ComposeNotificationTb4b4b4.Te6edf3TypeTb4b4b4.Te6edf3None
Te6edf3NotificationTb4b4b4.Te6edf3TypeTb4b4b4.Te6edf3Info Tff7b72-Tff7b72> Te6edf3ComposeNotificationTb4b4b4.Te6edf3TypeTb4b4b4.Te6edf3Info
Te6edf3NotificationTb4b4b4.Te6edf3TypeTb4b4b4.Te6edf3Warning Tff7b72-Tff7b72> Te6edf3ComposeNotificationTb4b4b4.Te6edf3TypeTb4b4b4.Te6edf3Warning
Te6edf3NotificationTb4b4b4.Te6edf3TypeTb4b4b4.Te6edf3Error Tff7b72-Tff7b72> Te6edf3ComposeNotificationTb4b4b4.Te6edf3TypeTb4b4b4.Te6edf3Error
Tb4b4b4}
Tff7b72return Te6edf3_fallbackNotificationsTb4b4b4.Te6edf3tryEmitTb4b4b4(
Te6edf3ComposeNotificationTb4b4b4(Te6edf3notificationTb4b4b4.Te6edf3titleTb4b4b4, Te6edf3notificationTb4b4b4.Te6edf3messageTb4b4b4, Te6edf3composeTypeTb4b4b4)Tb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tff7b72override Tff7b72fun Td2a8ffcancelTb4b4b4(Te6edf3idTb4b4b4: Tffa657IntTb4b4b4) Tb4b4b4{
T8b949e// Native OS notifications are fire-and-forget; cancel is best-effort.
Te6edf3LoggerTb4b4b4.Te6edf3d Tb4b4b4{ Ta5d6ff"Ta5d6ffcancel(Tffd700$Te6edf3idTa5d6ff) — not supported by current native sendersTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tff7b72override Tff7b72fun Td2a8ffcancelAllTb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// Native OS notifications are fire-and-forget; cancelAll is best-effort.
Te6edf3LoggerTb4b4b4.Te6edf3d Tb4b4b4{ Ta5d6ff"Ta5d6ffcancelAll() — not supported by current native sendersTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.05s